package com.yc.cloud.admin.service.impl;

import com.yc.cloud.admin.service.UmsResourceCacheService;
import com.yc.cloud.basic.constants.RedisKeyConstants;
import com.yc.cloud.basic.service.RedisService;
import com.yc.cloud.entity.UmsResource;
import lombok.val;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class UmsResourceCacheServiceImpl implements UmsResourceCacheService {
    @Resource
    private RedisService<UmsResource> redisService;

    @Override
    public UmsResource getByKey(String key) {
        return null;
    }

    @Override
    public void setByKey(String key, UmsResource umsResource) {

    }

    @Override
    public void setByKey(String key, UmsResource umsResource, long expire) {

    }

    @Override
    public boolean existByKey(String key) {
        return false;
    }

    @Override
    public List<UmsResource> listByKey(String key, long pageNum, long pageSize) {
        return null;
    }

    @Override
    public void delByKey(String key) {
        redisService.del(key);
    }

    @Override
    public List<UmsResource> listAllByKey(String key) {
        return redisService.lRange(key, 0, -1);
    }

    @Override
    public void lPushAllByCollectionByKey(String key, List<UmsResource> list) {
        redisService.lPushAllByCollection(key, list, expire);
    }

    @Override
    public UmsResource get(Long id) {
        return null;
    }

    @Override
    public void set(Long id, UmsResource umsResource) {

    }

    @Override
    public boolean exist(Long id) {
        return false;
    }

    @Override
    public List<UmsResource> list(long pageNum, long pageSize) {
        return null;
    }

    @Override
    public List<UmsResource> listAll() {
        return null;
    }

    @Override
    public void del(Long id) {

    }

    @Override
    public List<UmsResource> getByUserName(String username) {
        val key = getUserNameRealKey(username);
        return listAllByKey(key);
    }

    @Override
    public void setByUserName(String username, List<UmsResource> resourceList) {
        val key = getUserNameRealKey(username);
        lPushAllByCollectionByKey(key, resourceList);
    }

    @Override
    public void delByUserName(String username) {
        val key = getUserNameRealKey(username);
        delByKey(key);
    }

    private String getUserNameRealKey(String username) {
        return RedisKeyConstants.ADMIN_RESOURCE.replace(RedisKeyConstants.USERNAME, username);
    }
}
